<admintpl file="header" />
<link href="__TMPL__Public/assets/css/css-loader.css" rel="stylesheet" />
<link href="__TMPL__Public/assets/js/lobibox-master/dist/css/lobibox.min.css" rel="stylesheet" />
</head>
<body>
    <div class="loader loader-default" data-text="页面加载中···"></div>
    <div class="wrap js-check-wrap">
        <ul class="nav nav-tabs">
            <li><a href="{:U('PaymentReview/index')}">工程款支付报审表管理</a></li>
            <if condition="I('request.isUpload/s','') eq '1'">
            	<li><a href="{:U('PaymentReview/edit', array('id'=>I('request.id/s','')))}">新增工程款支付报审</a></li>
                <li class="active"><a href="#">现场工程量计量表</a></li>
            <else />
                <if condition="($Role eq 2) AND ($userrole['role'] eq 5)">
                    <li><a href="{:U('PaymentReview/add')}">新增工程款支付报审</a></li>
                </if>
                <li><a href="{:U('PaymentReview/view', array('id'=>I('request.id/s','')))}">查看工程款支付报审</a></li>
                <li class="active"><a href="{:U('PaymentReview/projectview', array('id'=>I('request.id/s','')))}">工程量清单报审表</a></li>
            </if>
            
        </ul>
        <form class="well form-search form-inline content" method="post" action="">
            <div class="form-group">
            	<label ></label>
                <select class="exceltype form-control" name="exceltype" id="exceltype">
                    <foreach name="excel" item="vo">
                        <option value="{$key}">{$vo}</option>
                    </foreach>
                </select>
                <if condition="I('request.isUpload/s','') eq '1'">
                	<input type="hidden" name="id" id="tableid" value="{:I('request.id/s','')}">
                	&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="javascript:void(0);" class="btn upBtn btn-primary" name="attachment" >选择文件</a>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                	<a href="javascript:void(0);" class="btn impBtn btn-primary" >导入</a>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                	<a href="javascript:void(0);" class="btn pubBtn btn-danger" >提交</a>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                	<a href="{:U('PaymentReview/edit', array('id'=>I('request.id/s','')))}" class="btn backBtn btn-warning" >返回</a>
                    <input type="file" id="upFile" name="upFile" style="display:none" />
                </if>
            </div>
        </form>
        <div class="showContent">
        
        </div>
    </div>
    <script src="__PUBLIC__/js/common.js"></script>
    <script type="text/javascript">
		$(document).ready(function(e) {
            $(".exceltype").change(function(){
				getData();
			});
            getData = function(){
                var reqUrl = "{:U('PaymentReview/technicalview', array('id'=>I('request.id/s',''), 'isAudit' => I('request.isAudit/s',''), 'level' => I('request.level/s',''), 'deptId' => I('request.deptId/s','')))}&type=" + $(".exceltype").val();
				//var reqUrl = "{:U('PaymentReview/technicalview', array('id'=>I('request.id/s','')))}&type=" + $(".exceltype").val();
				$(".showContent").load(reqUrl);
			}
			getData();
			
			window.obj = '';
			// 选择图片
			$(document).on("click", ".upBtn", function(e) {
				window.obj = $(this);
				$("#upFile").click();
			});
			// 文件选择器change事件
			$("#upFile").on("change", function(){
				uploadFiles();
			});
			uploadFiles = function(){
				if($("#upFile").val() == ""){
					alert("请选择待上传文件！");
					return false;
				}
				var name = window.obj.attr("name");
				var obj = window.obj;
				var imageURL = obj.next().find("input[name='"+name+"_filePath']").val() != undefined 
						?  obj.next().find("input[name='"+name+"_filePath']").val() 
						: "" ;
				
				$.ajaxFileUpload({
					url : "{:U('PaymentReview/upload')}",
					secureuri : false, //安全协议
					fileElementId:'upFile', //id
					type : 'post',
					dataType : 'json',
					data:{
						'imageURL' :  imageURL,
						'folder'   : "payment_review",
						'ajax': 1
					},
					async : false,
					error : function(data,status,e) {
						alert("服务器内部错误！");
					},
					success : function(json){
						if (json.rtnType == 'T'){
							html = "<span class='controls' style='margin-left:10px;'>   \n"
								+ "	<input type='hidden' name='"+name+"' value='"+json.rtnResult+"' />    \n"
								+ "	<input type='hidden' name='"+name+"_name' value='"+json.file_name+"' />    \n"
								+ json.file_name
								+ "</span>";
							$(".controls").remove();
							obj.after(html);
						} else {
							alert(json.rtnMsg);
						}
					},
					complete: function(xmlHttpRequest) {
						$("#upFile").replaceWith('<input type="file" id="upFile" name="upFile" style="display:none" />');
						$("#upFile").on("change", function(){
							uploadFiles();
						});
					}
				});
			}
			
			// 点击导入
			$('.impBtn').click(function(){
				$.ajax({
					type: "POST",
					url: "{:U('PaymentReview/addPostFile')}",
					data: $('form.content').serialize(),
					beforeSend: function(XMLHttpRequest){

						var inobj = $("input[name='attachment']");
						if (inobj.val() == undefined || inobj.val() == '') {

						    alert("请选择文件");
						    //Lobibox.alert("error",{msg: "请选择文件",title: '系统提示'});
						    return false;
						}
						else {
						    $(".loader").show();
						    $(".loader").addClass("is-active").attr("data-text", "正在处理，请稍等片刻~");
						}
					},
					success: function(data){
						if(data.state == "fail"){
							alert(data.info);
						}
						$(".upBtn").next("span").remove();
						getData();
					    //加载完毕移除加载动画
						$(".loader").removeClass("is-active");
						$(".loader").hide();
					},
					error: function(){}
				});
			});
			
			// 点击提交
			$('.pubBtn').click(function(){
				$.ajax({
					type: "POST",
					url: "{:U('PaymentReview/publishs')}",
					data: {
						"exceltype"	: $("#exceltype").val(),
						"sheet"		: $("select.sheetType").find("option:selected").text(),
						"id"		: $("#tableid").val(),
						"AJAX"		: 1
					},
					beforeSend: function(XMLHttpRequest){
						var type = $("#exceltype").val();
						var length = $(".showContent tbody").find("td.bg-danger").length;
						if(length > 0){
						    alert("本期上报数据与累计上报数据之和不能超过清单量，请修正后再提交");
							return false;
						}
					},
					success: function(data){
						alert("提交成功");
					},
					error: function(){}
				});
			});



    });
	</script>
</body>
</html>